package com.gxuwz.lhleavesys.service.impl;

import com.gxuwz.lhleavesys.dao.StudentDao;
import com.gxuwz.lhleavesys.entity.Student;
import com.gxuwz.lhleavesys.entity.User;
import com.gxuwz.lhleavesys.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    public boolean registerUser(User user) throws Exception {
        return true;
    }

    /*
     * public void disableUser(String userid)throws Exception{
     * Student student = new Student();
     * student.setStuID(userid);
     * studentDao.update(user);
     * }
     */

    /**
     * 添加用户
     *
     * @param student
     * @return
     * @throws Exception
     */
    public boolean addUser(Student student) throws Exception {
        return studentDao.insert(student);
    }

    public Student findStudentBystuID(String id) throws SQLException {
        return studentDao.findStudentBystuID(id);
    }

    /**
     * 修改学生
     * 
     * @param student
     * @throws Exception
     */
    public boolean update(Student student, String id) throws SQLException {
        return studentDao.update(student, id);
    }

    /**
     * 删除用户
     * 
     * @param userid
     * @throws Exception
     */

    public boolean deleteStudent(String userid) throws SQLException {
        return studentDao.delete(userid);
    }

    @Override
    public boolean checkUser(String name, String password) throws SQLException {
        Student student = new Student();
        student.setName(name == null ? "0" : name);
        student.setPassword(password == null ? "0" : password);
        List<Student> list = studentDao.query(student);
        return !list.isEmpty();
    }

    @Override
    public Student findByNameStudent(String name) {
        return studentDao.findByName(name);
    }

    @Override
    public Student findstuNoBystuName(String name) throws SQLException {
        return studentDao.findstuNoBystuName(name);
    }

    public List<User> listUser() {
        return new ArrayList<User>();
    }

    public void setStudentDao(StudentDao studentDao) {
        this.studentDao = studentDao;
    }

    @Override
    public List<Student> getStudentByinstructor(String collegeID) {
        return studentDao.getStudentByinstructor(collegeID);
    }

    @Override
    public void add(String name, String password) {

    }

    @Override
    public User user() throws SQLException {
        return null;
    }

    @Override
    public void edit(User user) {

    }

    @Override
    public void delete(String username) {

    }

    @Override
    public Student findByName(String name) {
        return null;
    }

    @Override
    public Student findByID(String id) {
        return null;
    }
}
